<template>
  <el-dialog :title="`${isEdit ? '编辑' : '新增'}考勤`" :visible.sync="dialogVisible" width="30%" :close-on-click-modal="false" :before-close="close">
    <div>
      <el-form ref="RefForm" :model="formData" label-width="120px" :rules="formRules" status-icon>
        <el-form-item label="部门" prop="deptCode">
          <el-input v-model="formData.deptCode"></el-input>
        </el-form-item>
        <el-form-item label="员工" prop="deptName">
          <el-input v-model="formData.deptName"></el-input>
        </el-form-item>
        <el-form-item label="考勤状态" prop="number">
          <el-input v-model="formData.number"></el-input>
        </el-form-item>
        <el-form-item label="进出隧道时间" prop="deptCode">
          <el-input v-model="formData.deptCode"></el-input>
        </el-form-item>
        <el-form-item label="进出打卡设备" prop="number">
          <el-input v-model="formData.number"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="number">
          <el-input v-model="formData.number"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button :loading="loadingSubmit" type="primary" @click="handleSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import dialogEditMixin from '@/mixins/dialogEdit'
  //   import { eleValidator } from '@/utils/tools'
  import { user } from '@/api/api'
  export default {
    mixins: [dialogEditMixin],
    data() {
      // const _this = this
      return {
        options: [],
        formRules: {
          deptCode: [
            { required: true, message: '请输入部门编码', trigger: 'blur' }
          ],
          deptName: [
            { required: true, message: '请输入部门名称', trigger: 'blur' }
            // {
            //   validator: eleValidator([
            //     { rule: 'isChinese', msg: '密码不能包括中文' }
            //   ]),
            //   trigger: 'blur'
            // }
          ]
        },
        apiKey: {
          search: 'department/search',
          add: 'department/add',
          put: 'department/put'
        }
      }
    },
    mounted() {
      this.getDepartmentList()
    },
    methods: {
      resetFormData() {
        this.formData = {
          deptCode: '',
          deptName: '',
          number: ''
        }
      },
      async getDepartmentList() {
        let obj = { pageIndex: 1, pageSize: 10 }
        const result = await user('get', obj, false)
        if (result.code === 200) {
          this.options = []
          result.data.items.forEach(item => {
            this.options.push({
              label: item.deptName,
              value: item.id
            })
          })
        }
      }
    }
  }
</script>

<style lang="scss" scoped></style>
